//
//  MMGComposeViewController.swift
//  MyMicroblog
//
//  Created by Mac on 17/1/4.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class MMGComposeViewController: MMGBaseViewController, SWSquareControllerDelegate {

    var squareView:UIView?
    var moveInstance:CGFloat = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
//        let toolBar = UIToolbar(frame: UIScreen.main.bounds)
//        toolBar.barStyle = .black
        view.addSubview(backImageView)
        view.addSubview(sologImageView)
        
        sologImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(100)
        }
        
        let squareHeight:CGFloat = 300
        let squareY = view.bounds.height - squareHeight - 80
        
        let squareController:SWSquareController = SWSquareController()
        squareController.delegate = self
        squareController.view.frame = CGRect(x: 0, y: squareY, width: view.bounds.width, height: squareHeight)
        addChildViewController(squareController)
        view.addSubview(squareController.view)
        squareView = squareController.view
    }
    
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage.snapShotCurrentWindow().applyLightEffect())
    private lazy var sologImageView: UIImageView = UIImageView(image: #imageLiteral(resourceName: "compose_slogan"))
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        UIView.animate(withDuration: 0.25, animations: {
            self.view.removeFromSuperview()
            self.removeFromParentViewController()
        })
    }

}

extension MMGComposeViewController {

    func startComposeController() {
        
//        let parentCtr = parent?.childViewControllers[(self.parent?.childViewControllers.count)! - 2]
        let editCtr = MMGReleaseInformationViewController()
        // 移除
        self.view.removeFromSuperview()
        self.removeFromParentViewController()
        // 跳转页面
        let nav = MMGNavigationController(rootViewController: editCtr)
        UIView.animate(withDuration: 0.25) {
            UIApplication.shared.keyWindow?.rootViewController?.present(nav, animated: true, completion: nil)
        }
        
    }
}
